home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Night Owl 6
/
Night Owl's Shareware - PDSI-006 - Night Owl Corp (1990).iso
/
015a
/
decide22.zip
/
DECIDE.DOC
next >
Wrap
Text File
|
1992-02-04
|
11KB
|
269 lines
DECIDE .BAT file tool FLOWtools(tm)
────────────────────────────────────────────────────────────────────────
┌────────────────────────────────────────────────╖
│ DECIDE -- BAT Prompter Version 2.2 ║
│ Copyright (c) 1991 by FLOW Research, Inc. ║
│ All Rights Reserved. ║
╘════════════════════════════════════════════════╝
NAME
Decide -- multiple-choice branching in .BAT files
SYNOPSIS
Decide [/optlist] [-num] [prompt]
DESCRIPTION
DECIDE fills a gap in the utilities that come standard with
MS-DOS. DOS supports the automation of repetitive tasks with
"Batch" files. In their most basic form, these are text files
containing a list of valid DOS commands. By giving the file a
name with a .BAT extension, it becomes possible to use the
file as a DOS command.
Unfortunately, there is no simple way to make batch files
interactive. Early versions of DOS had only the PAUSE command
to allow changing floppy disks. Many versions of DOS now come
with some sort of ASK utility which lets a batch file do one
thing or another based on your answer to a Yes/No question.
DECIDE addresses two problems: first, that many questions you
would like to ask in a batch file can't be answered by Yes or
No; second, that you would sometimes like the batch file to
do something if you don't answer at all -- for instance, if
you're on the road and dialing in to your computer, or even if
you just turned it on and went for coffee.
DECIDE works by using two poorly-documented and underutilized
features of DOS's batch-command language, to wit:
IF ERRORLEVEL <x> and
GOTO <label>
The "DOS errorlevel" is a special value which programs can set
when they stop running and return you to DOS. Its original
intention was to let programs indicate some kind of error
condition. With DECIDE, you can use the DOS errorlevel to make
batch files as sophisticated as some "DOS shell" programs.
A typical DECIDE command line in a batch file looks like this:
DECIDE /WEF WordPerfect, Excel, FoxBase
When DOS reaches the line in your batch file containing the
DECIDE command as shown above, the following will appear on
your screen:
WordPerfect, Excel, FoxBase (W/E/F)?
You may then press one of the three indicated keys ('w', 'e'
or 'f'). Pressing ENTER is the equivalent of pressing the
first key in the list (in our example, 'w'). If you press any
other key you will see the following on your screen:
Please choose one from the list.
WordPerfect, Excel, FoxBase (W/E/F)?
When you press one of the allowable keys (or ENTER), DECIDE
quits. However, when it quits it sets the DOS error-level
value to match the key you pressed. Again using the example
above, if you pressed ENTER or W (or w) the DOS error level
would be 0. If you pressed E, it would be 1. If you pressed F,
it would be 2. The allowed keys are all specified with a
forward-slash ('/'), followed by up to 20 characters with
no intervening spaces.
To use this error level in you batch file, you need some lines
after the DECIDE command to, well, decide what to do next.
Let's expand on the example above:
DECIDE /WEF WordPerfect, Excel, FoxBase
if errorlevel 2 echo Do WordPerfect
if errorlevel 1 echo Do Excel
if errorlevel 0 echo Do FoxBase
Each "if errorlevel" line tests for a value of the DOS
errorlevel. If the DOS errorlevel is AT LEAST the value
specified in the line, DOS will do whatever is in the line
after the "if errorlevel <x>." This "at least" has to do with
the original intention of the DOS errorlevel as an error
indicator. If you were to type the four lines above into a .BAT
file, and ran it, the result when you pressed 'e' would be
Do Excel
Do FoxBase
This is because DOS will interpret as true any "if
errorlevel" statement that specifies a value EQUAL TO OR LESS
THAN the current errorlevel. See the examples for the proper
syntax of batch files using DECIDE.
The next option in DECIDE lets you program a countdown. Let's
modify the example we've already seen:
DECIDE /WEF -5 WordPerfect, Excel, FoxBase
When you run this from the DOS prompt or from within a batch
file, the prompt would be:
5 WordPerfect, Excel, FoxBase (W/E/F)?
Unless you press a key immediately, you will see the '5'
become '4' after one second, then '3', etc. When it reaches
0, DECIDE will quit to DOS with the DOS error level set to 0.
In other words, if you press no key for five seconds, it will
have the same effect as if you had pressed 'W' or ENTER. This
can be used to create batch files with a certain "default"
behavior, but which can behave differently if you wish at the
press of a key. You can specify a delay of up to 60 seconds.
The best way to understand this feature is to look at the
examples.
Here is a summary of the DECIDE command-line options.
Options: /(characters) Allowed key responses
-(number) Delay in seconds
(Anything else) Part of prompt
DECIDE with no command-line parameters will display a brief
usage message. DECIDE /V will display the program's version
number and copyright notice, then quit.
If no text is specified for the prompt, the program will use
the message "Run" as a default. If no key-response list is
specified, it will use /YN as a default. Thus the simplest
possible DECIDE command line is simply:
DECIDE -10
which will produce the prompt
Run (Y/N)?
and countdown for 10 seconds before defaulting to response Y.
EXAMPLES
In the examples that follow, the line "echo off" at the top
of each sample batch file prevents the commands in the rest
of the file from being displayed on the screen before DOS
runs them. Lines of the form ":label" are the standard format
for indicating the place to which a batch file "goto" command
should continue running. Refer to your DOS manual for more
information on these and other batch file commands.
Example 1 -- batch file using DECIDE to load Windows 3.0
───────────────────────────────────────────────────────────────
echo off
DECIDE -15 /NRSE Windows: None, Real Mode, Standard, Enhanced
if errorlevel 3 goto wenh
if errorlevel 2 goto wstd
if errorlevel 1 goto wreal
REM if we got here errorlevel is 0
goto done
:wenh
WIN /E
goto done
:wstd
WIN /S
goto done
:wreal
WIN /R
goto done
:done
REM end of batch file
───────────────────────────────────────────────────────────────
The effect of this batch file is to give you 15 seconds to
decide in which mode you would like to run Windows. If you
don't make up your mind in 15 seconds, or if you walk away
from your PC, the batch file will simply quit to DOS without
running Windows at all.
Example 2 -- an AUTOEXEC.BAT file for an occasional BBS Sysop
───────────────────────────────────────────────────────────────
echo off
REM no key-response list specified so DECIDE uses default /YN
DECIDE -50 Load BBS
if errorlevel 1 goto nobbs
REM if we got here we should load the BBS
SEADOG -REALLY -Arduous -Option -List
SET PATH=C:\TBBS;C:\TBBS\EXTRA;C:\TBBS\FILES
REM Chain to the batch file that loads the BBS software
C:
CD \TBBS
RUNBBS
REM next line is pro-forma since we never return from
REM the chain-command to RUNBBS.BAT
goto done
:nobbs
REM BBS not loaded, do non-BBS kinds of things
SET PATH=C:\NONBBS;C:\KINDSOF\THINGS;C:\GAMES
:done
───────────────────────────────────────────────────────────────
The above example shows a way of using DECIDE to, well, decide
which batch file you want to run.
Example 3 -- an AUTOEXEC.BAT file for an *Infrequent* BBS Sysop
───────────────────────────────────────────────────────────────
echo off
REM Explicitely make key-response list /NY to make N default
DECIDE -50 /NY Load BBS
if errorlevel 1 goto Loadbbs
goto nobbs
:Loadbbs
REM if we got here we should load the BBS
SEADOG -REALLY -Arduous -Option -List
SET PATH=C:\TBBS;C:\TBBS\EXTRA;C:\TBBS\FILES
REM Chain to the batch file that loads the BBS software
C:
CD \TBBS
RUNBBS
REM next line is pro-forma since we never return from
REM the chain-command to RUNBBS.BAT
goto done
:nobbs
REM BBS not loaded, do non-BBS kinds of things
SET PATH=C:\NONBBS;C:\KINDSOF\THINGS;C:\GAMES
:done
───────────────────────────────────────────────────────────────
This example shows how to change the default behavior when
using DECIDE's timer feature. We have only specified /NY
instead of the default /YN as our key-response list, we
have changed the meaning of pressing 'N' to set the error
level to 0 instead of 1 (as in Example 2). A little change
in the "errorlevel" test and the use of "goto" and voilà!
The batch file will NOT run the BBS if no key is pressed.
While these examples may make DECIDE sound complicated, it is
really a very simple program, that solves a simple problem
simply. Like so many shareware utilities, it should have
been included with MS-DOS.
NOTES
See FLOWREAD.ME for license terms, restrictions, and source
code availability.
TECHNICAL
DECIDE traps the Ctrl-Break signal, displays an "Aborted"
message, and quits with an errorlevel of 0. It uses no
file I/O or memory allocation and has a "petite" stack,
so it should run without fail in many situations, even
after a badly-behaved program has "retouched" memory.
AUTHOR
Daniel Gross
FLOW Research, Inc.
119 Avenue D, #4
New York NY 10009